home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Revolution - Das Atari CD Magazin 1997
/
Revolution - Das Atari CD Magazin 1.iso
/
software
/
anwendng
/
qed_397
/
sourcen
/
event.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-08
|
12KB
|
562 lines
#include "global.h"
#include "av.h"
#include "clipbrd.h"
#include "dd.h"
#include "disk.h"
#include "edit.h"
#include "find.h"
#include "icon.h"
#include "magx.h"
#include "menu.h"
#include "makro.h"
#include "olga.h"
#include "projekt.h"
#include "rsc.h"
#include "se.h"
#include "set.h"
#include "string.h"
#include "text.h"
#include "windows.h"
#include "event.h"
#include "debug.h"
/****** DEFINES **************************************************************/
#ifndef WM_BOTTOMED
#define WM_BOTTOMED 33
#endif
#ifndef WM_ICONIFY
#define WM_ICONIFY 34
#define WM_UNICONIFY 35
#define WM_ALLICONIFY 36
#endif
#ifndef SH_WDRAW
#define SH_WDRAW 72
#endif
#define MAX_EVENT 20
/****** TYPES ****************************************************************/
typedef struct
{
WORD event;
WORD msg[8];
MKINFO mk;
}qedEVENT;
/****** VARIABLES ************************************************************/
LOCAL qedEVENT msg_queue[MAX_EVENT];
LOCAL WORD msg_head = 0,
msg_tail = 0;
LOCAL WORD old_mx = 0,
old_my = 0; /* Immer die letzte Mausposition */
WORD abortProg = FALSE; /* wird TRUE bei SIGTERM */
/****** FUNCTIONS ************************************************************/
LOCAL VOID hndl_keybd (MKINFO *mk);
LOCAL VOID hndl_button (MKINFO *mk);
LOCAL VOID hndl_msg (WORD *msg, MKINFO *mk);
/*****************************************************************************/
VOID gem2mk(WORD kreturn, WORD kstate, MKINFO *mk)
{
mk->kstate = kstate;
mk->scan_code = kreturn;
mk->kreturn = normkey (kstate, kreturn);
mk->ascii_code = mk->kreturn & 0x00FF;
if (mk->kreturn & NKF_SHIFT) /* beide SHIFT Tasten setzen */
mk->kreturn |= NKF_SHIFT;
mk->kreturn &= ~NKF_CAPS; /* CAPSLOCK löschen */
mk->shift = (kstate & (K_RSHIFT | K_LSHIFT)) != 0;
mk->ctrl = (kstate & K_CTRL) != 0;
mk->alt = (kstate & K_ALT) != 0;
}
LOCAL BOOLEAN is_event(VOID)
{
return (msg_head!=msg_tail);
}
LOCAL BOOLEAN full_event(VOID)
{
WORD next;
next = msg_head+1;
if (next==MAX_EVENT)
next = 0;
return(next==msg_tail);
}
LOCAL VOID add_event(qedEVENT *event)
{
WORD next;
if (event->event==MU_KEYBD && is_event()) /* Tastatur-Repeat? */
{
qedEVENT *ptr = &msg_queue[msg_tail];
if (ptr->event == MU_KEYBD && ptr->mk.scan_code == event->mk.scan_code &&
ptr->mk.kstate == event->mk.kstate)
return;
}
next = msg_head + 1;
if (next==MAX_EVENT)
next = 0;
if (next==msg_tail)
{
inote(1,FATALERR,10);
return;
}
msg_queue[msg_head] = *event;
msg_head = next;
}
LOCAL BOOLEAN get_event(qedEVENT *event)
{
if (msg_head!=msg_tail)
{
*event = msg_queue[msg_tail];
msg_tail++;
if (msg_tail==MAX_EVENT) msg_tail = 0;
return TRUE;
}
return FALSE;
}
BOOLEAN idle (VOID)
{
qedEVENT ev;
WORD events, kreturn, kstate;
if (full_event())
return FALSE;
events = MU_KEYBD | MU_BUTTON | MU_MESAG | MU_TIMER;
if (Mouse_sleeps())
events |= MU_M2;
ev.event = evnt_multi (events,
0x102, 3, 0,
0, 0, 0, 0, 0,
1, old_mx, old_my, 1, 1,
ev.msg,
0, 0,
&old_mx, &old_my,
&ev.mk.mobutton, &kstate,
&kreturn, &ev.mk.breturn);
if (ev.event!=MU_TIMER)
{
ev.event &= (~MU_TIMER);
if (ev.event == MU_M2)
Wake_mouse();
else
{
ev.mk.mox = old_mx;
ev.mk.moy = old_my;
gem2mk(kreturn, kstate, &ev.mk);
add_event(&ev);
}
return TRUE;
}
return FALSE;
}
BOOLEAN abbruch (VOID)
{
qedEVENT ev;
WORD events, kreturn, kstate;
if (full_event())
events = MU_KEYBD | MU_TIMER;
else
{
events = MU_KEYBD | MU_BUTTON | MU_MESAG | MU_TIMER;
if (Mouse_sleeps())
events |= MU_M2;
}
ev.event = evnt_multi (events,
0x102, 3, 0,
0, 0, 0, 0, 0,
1, old_mx, old_my, 1, 1,
ev.msg,
0, 0,
&old_mx, &old_my,
&ev.mk.mobutton, &kstate,
&kreturn, &ev.mk.breturn);
if (ev.event!=MU_TIMER)
{
ev.event &= (~MU_TIMER);
if (ev.event==MU_M2)
{
Wake_mouse();
return FALSE;
}
ev.mk.mox = old_mx;
ev.mk.moy = old_my;
gem2mk(kreturn, kstate, &ev.mk);
if (ev.event & MU_KEYBD) /* andere Tasten schlucken */
{
return (ev.mk.kreturn & NK_ESC);
}
add_event(&ev);
}
return FALSE;
}
LOCAL VOID next_action(qedEVENT *ev)
{
WINDP window;
WORD events, f, kreturn, kstate;
RECT r;
again:
if (get_event(ev)) /* Event aus der Schlange */
{
old_mx = ev->mk.mox;
old_my = ev->mk.moy;
if (makro_play)
{
if (ev->event != MU_KEYBD)
{
end_play();
return;
}
else if (ev->mk.kreturn | NK_ESC)
{
end_play();
goto again;
}
}
else
return;
}
if (pre_makro(&ev->mk)) /* Event vom Makro */
{
ev->event = MU_KEYBD;
return;
}
/* auf Event warten */
events = MU_KEYBD | MU_BUTTON | MU_MESAG | MU_TIMER;
if (Mouse_sleeps())
events |= MU_M2;
if (top() == NULL)
events &= (~MU_TIMER);
window = real_top();
if (window!=NULL && window->flags & WI_MOUSE) /* Mein Fenster ist oberstes */
{
events |= MU_M1;
r = window->work;
f = inside(old_mx,old_my,&r);
if (!f)
{
if (Get_mouse()!=ARROW)
Arrow_mouse();
}
else
{
if (Get_mouse()!=window->mousenum)
Set_mouse (window->mousenum);
}
}
else
{
if (Get_mouse()!=ARROW)
Arrow_mouse();
}
ev->event = evnt_multi (events,
0x102, 3, 0,
f, r.x, r.y, r.w, r.h,
1, old_mx, old_my, 1, 1,
ev->msg,
500, 0,
&old_mx, &old_my,
&ev->mk.mobutton, &kstate,
&kreturn, &ev->mk.breturn);
ev->mk.mox = old_mx;
ev->mk.moy = old_my;
gem2mk(kreturn, kstate, &ev->mk);
}
/*****************************************************************************/
/* Ereignis-Verarbeitung */
/*****************************************************************************/
LOCAL VOID hndl_keybd (MKINFO *mk)
{
WINDOWP window;
post_makro(mk);
if (!makro_play)
Sleep_mouse ();
window = top(); /* Taste an TOP-Fenster */
if (window == NULL)
window = get_window(0); /* DESKTOP suchen */
if (window == NULL)
return;
if (key_window(window,mk)) /* oberstes Fenster */
return;
else
{
if (window->class != DESK) /* war nicht DESKTOP */
{
window = get_window(0); /* DESKTOP suchen */
if (window==NULL)
return;
if (key_window(window,mk)) /* an Hauptprogramm */
return;
}
}
}
/*****************************************************************************/
LOCAL VOID hndl_button (MKINFO *mk)
{
WORD wh;
WINDP window;
if (!all_iconified)
{
Wake_mouse();
wh = wind_find (mk->mox, mk->moy); /* Hole Window Handle */
window = find_window (wh); /* Hole Window */
if (window != NULL)
click_window(window, mk); /* Selektiere */
}
else
if (!no_desktop)
mybeep();
} /* hndl_button */
/*****************************************************************************/
LOCAL VOID hndl_msg (WORD *msg, MKINFO *mk)
{
WINDOWP window;
UBYTE *str_p;
Wake_mouse();
window= find_window (msg[3]); /* Zugehöriges Fenster */
switch (msg[0]) /* Art der Nachricht */
{
case MN_SELECTED:
if (makro_rec) /* Makro wird Tastendruck vorgegaukelt */
{
MKINFO l_mk;
str_p = (UBYTE *)get_obspec(menu, msg[4]);
if (str_to_key(str_p ,&l_mk))
{
l_mk.kstate |= (mk->kstate&3);
post_makro(&l_mk);
}
}
hndl_menu (msg[3], msg[4], ((mk->kstate & 4) != 0));
break;
case WM_REDRAW :
redraw_window (window, (RECT*)(msg+4));
break;
case WM_CLOSED :
if (no_desktop)
do_icon(window->link, DO_DESTRUCT);
else
do_icon(window->link, DO_CLOSE);
break;
case WM_FULLED :
full_window (window);
break;
case WM_ARROWED :
arrow_window (window, msg[4], 1);
break;
case WM_HSLID :
h_slider (window, msg[4]);
break;
case WM_VSLID :
v_slider (window, msg[4]);
break;
case WM_SIZED :
size_window (window, (RECT*)(msg+4), TRUE);
break;
case WM_MOVED :
move_window (window, (RECT*)(msg+4));
break;
case WM_NEWTOP : /* Fenster von qed ist irgendwie nach oben gekommen */
case WM_ONTOP :
ontop_window(window);
break;
case WM_TOPPED :
top_window (window);
do_all_icon(edit_type, DO_UPDATE); /* Schreibschutz? */
break;
case WM_UNTOPPED: /* qed hat jetzt nicht mehr das Top-Fenster */
untop_window (window);
break;
case WM_BOTTOMED: /* nur gem >= 0x400 : Fenster nach hinten */
case WM_M_BDROPPED : /* nur Magic */
bottom_window (window, msg[0]);
break;
case WM_ICONIFY:
iconify_window(window, (RECT*)(msg+4), FALSE);
break;
case WM_ALLICONIFY:
alliconify((RECT*)(msg+4));
break;
case WM_UNICONIFY:
uniconify_window(window, (RECT*)(msg+4));
break;
case AP_TERM:
if (all_iconified)
uniconify_window(NULL, NULL); /* aufwachen! */
quick_close = TRUE;
if (Icon_test(0,DO_DESTRUCT))
Icon_edit(0,DO_DESTRUCT);
break;
case AP_DRAGDROP :
if (all_iconified)
uniconify_window(NULL, NULL);
hndl_dd(msg);
break;
case SC_CHANGED :
do_icon(iclipbrd, DO_UPDATE);
break;
case VA_START :
case VA_PROTOSTATUS :
case VA_DRAG_COMPLETE :
hndl_av(msg);
break;
case SE_INIT:
case SE_OK:
case SE_ACK:
case SE_OPEN:
case SE_ERROR:
case SE_ERRFILE:
case SE_PROJECT:
case SE_QUIT:
case SE_TERMINATE:
case SE_CLOSE :
case SE_MENU :
if (all_iconified)
uniconify_window(NULL, NULL); /* aufwachen! */
hndl_se(msg);
break;
case OLGA_INIT :
case OLE_NEW :
case OLGA_ACK :
case OLE_EXIT :
hndl_OLGA(msg);
break;
/* ignorieren */
case SH_WDRAW :
break;
default:
#ifdef DEBUG
{
UBYTE str[12];
WORD d, i, id;
if ((appl_xgetinfo(4, &d, &d, &i, &d)) && (i == 1)) /* gibts appl_search? */
{
i = appl_search(0, str, &d, &id);
while (i != 0)
{
if (d == 2 && id == msg[1])
break;
i = appl_search( 1, str, &d, &id);
}
}
Debug("qed: Unbekannte Msg %d (0x%X) von %s (%d)\n", msg[0], msg[0], str, id);
}
#endif
break;
}
} /* hndl_msg */
/*****************************************************************************/
VOID hndl_events (VOID)
{
qedEVENT ev;
BOOLEAN menu_chg;
time_t t;
updt_menu();
menu_chg = FALSE;
onblink_edit();
do
{
quick_close = FALSE; /* Sichern der Texte ohne Nachfrage */
next_action (&ev);
wind_update (BEG_UPDATE); /* Keine Interaktion zulassen */
get_realtop();
global_shift = ((ev.mk.kstate & 3) != 0);
if (ev.event == MU_TIMER) /* Zeit (nur wenn nichts anderes anliegt) */
{
timer_se();
time(&t);
local_time = localtime(&t);
if (blinking_cursor)
blink_edit();
do_icon(iclipbrd, DO_UPDATE);
do_all_icon(ALL_TYPES, DO_AUTOSAVE);
}
if (ev.event & MU_KEYBD) /* Taste */
{
offblink_edit();
hndl_keybd(&ev.mk);
menu_chg = TRUE;
onblink_edit();
while (idle()) ; /* Auch für Makro-Play-Abbruch */
}
if (ev.event & MU_BUTTON) /* Mausknopf */
{
offblink_edit();
hndl_button(&ev.mk); menu_chg = TRUE;
onblink_edit();
}
if (ev.event & MU_MESAG) /* Meldung */
{
offblink_edit();
hndl_msg(ev.msg, &ev.mk); menu_chg = TRUE;
onblink_edit();
}
if (ev.event & MU_M2) /* Maus bewegt */
{
Wake_mouse();
}
if (menu_chg && !is_event()) /* Wenn Zeit */
{
updt_menu(); /* Eine Aktion kann Menüs verändern */
menu_chg = FALSE;
}
wind_update (END_UPDATE);
end_undo_seq();
if (abortProg)
{
WORD msg[] = {0,0,0,0,0,0,0,0};
msg[0] = AP_TERM;
msg[1] = gl_apid;
appl_write(gl_apid, 16, msg);
}
} while (! done);
Arrow_mouse ();
} /* hndl_events */